<template>
	<basic-container>
		<el-form :model="form" ref="form" label-width="100px">
			<el-form-item label="名称" prop="name" :rules="[{required: true,message: '请输入名称'},{min: 0,max: 255,message: '请输入名称'},]">
				<el-input v-model="form.name"></el-input>

			</el-form-item>
			<el-form-item label="性别" prop="sex" :rules="[{min: 0,max: 255,message: '请输入性别'},]">
       <el-select v-model="form.sex" placeholder="请选择">
            <el-option
              v-for="item in sexlist"
              :key="item.name"
              :label="item.name"
              :value="item.name">
            </el-option>
          </el-select>
			</el-form-item>
			<el-form-item label="出生日期" prop="birthDate" :rules="[]">
				<el-date-picker v-model="form.birthDate"  type="date" value-format="yyyy-MM-dd">
				</el-date-picker>

			</el-form-item>
			<el-form-item label="称呼" prop="calls">
        <el-select v-model="form.calls" placeholder="请选择">
             <el-option
               v-for="item in callslist"
               :key="item.name"
               :label="item.name"
               :value="item.name">
             </el-option>
           </el-select>

			</el-form-item>
			<el-form-item label="部门" prop="dept" :rules="[{min: 0,max: 255,message: '请输入部门'},]">
				<el-input v-model="form.dept"></el-input>

			</el-form-item>
			<el-form-item label="公司电话" prop="officePhone" :rules="[{min: 0,max: 255,message: '请输入地址公司电话'},]">
				<el-input type="number" v-model="form.officePhone"></el-input>

			</el-form-item>
			<el-form-item label="手机" prop="phone" :rules="[{required: true,message: '请输入手机号'},{min: 0,max: 255,message: '请输入手机号'},]">
				<el-input type="number" v-model="form.phone"></el-input>

			</el-form-item>
			<el-form-item label="家庭电话" prop="homePhone" :rules="[{min: 0,max: 255,message: '请输入家庭电话'},]">
				<el-input type="number" v-model="form.homePhone"></el-input>

			</el-form-item>
			<el-form-item label="职务" prop="post" :rules="[{min: 0,max: 255,message: '请输入地址职务'},]">
				<el-input v-model="form.post"></el-input>

			</el-form-item>
			<el-form-item label="邮编" prop="ybCode" :rules="[{min: 0,max: 255,message: '请输入地址邮编'},]">
				<el-input type="number" v-model="form.ybCode"></el-input>

			</el-form-item>
			<el-form-item label="Email" prop="email" :rules="[{min: 0,max: 255,message: '请输入Email'},]">
				<el-input v-model="form.email"></el-input>

			</el-form-item>
			<el-form-item label="地址" prop="address" :rules="[{min: 0,max: 255,message: '请输入地址'},]">
				<el-input v-model="form.address"></el-input>

			</el-form-item>
			<el-form-item label="爱好" prop="hobby">
				<el-input v-model="form.hobby"></el-input>

			</el-form-item>
			<el-form-item label="备注" prop="remake">
				<el-input v-model="form.remake"></el-input>

			</el-form-item>
		<!-- 	<el-form-item label="更新时间" prop="updateTime" :rules="[]">
				<el-date-picker v-model="form.updateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss">
				</el-date-picker> -->

			</el-form-item>
		</el-form>
		<div class="el-dialog__footer">
			<div slot="footer" class="dialog-footer">
				<el-button @click="cancelReturn()">取 消</el-button>
				<el-button type="primary" @click="save()">保 存</el-button>
			</div>
		</div>
	</basic-container>
</template>

<script>
	export default {
		name: "addContacts",
		props: {
			cancelReturn: {
				type: Function
			},
			id: {
				type: String
			},
			agreementNo: {
				type: String
			},
			customerJcName: {
				type: String
			},
			mainid: {
				type: String
			}
		},
		data() {
			return {
        callslist:[
          {
            name:'先生'
          },
          {
            name:'女士'
          }
        ],
        sexlist:[
          {
            name:'男'
          },
          {
            name:'女'
          }
        ],
				form: {
					name: undefined,
					sex: '男',
					birthDate: undefined,
					calls: '先生',
					dept: undefined,
					officePhone: undefined,
					phone: undefined,
					homePhone: undefined,
					post: undefined,
					ybCode: undefined,
					email: undefined,
					address: undefined,
					hobby: undefined,
					remake: undefined,
					updateTime: undefined,
					createUserId: undefined,
				}

			};
		},
		created() {
			console.log(this.agreementNo);
			console.log(this.customerJcName);
			if ("" != this.id && this.id != undefined) {
				this.getByid(this.id);
			}
		},
		methods: {
		   sendEmail() {
		                  var regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
		                  if (this.form.email != '' && !regEmail.test(this.form.email)) {
		                      this.$message({
		                          message: '邮箱格式不正确',
		                          type: 'error'
		                      })
		                      this.form.email = ''
		                  }
		              },
			getByid(id) {
				this.$http({
					url: this.$http.adornUrl(
						`/hotel/agreement-contacts/getbyid/` + id
					),
					method: "post",
				}).then(({
					data
				}) => {
					this.form = data.page;
				});
			},
			checkTime(i) {
				if (i < 10) {
					i = '0' + i
				}
				return i
			},
			// 表单提交
			save() {
				this.form.agreementId = this.mainid;
				this.$refs["form"].validate(valid => {
					if (valid) {
						this.$http({
							url: this.$http.adornUrl(
								`/hotel/agreement-contacts/${!this.form.id ? "save" : "update"}`
							),
							method: "post",
							data: this.form
						}).then(({
							data
						}) => {
							if (data && data.code === 0) {
								this.$message({
									message: "操作成功",
									type: "success",
									duration: 1500,
									onClose: () => {
										this.cancelReturn();
									}
								});
							} else {
								this.$message.error(data.msg);
							}
						});
					}
				});
			}
		}

	}
</script>

<style>
</style>
